/**
 * 
 */
package org.springside.examples.miniweb.service.report;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.examples.miniweb.dao.report.BackPumpReportDao;
import org.springside.examples.miniweb.entity.report.BackPumpReport;
import org.springside.examples.miniweb.entity.report.ColdPumpReport;
import org.springside.examples.miniweb.service.ServiceException;

/**
 * @author Eric 2012-3-6
 * 
 * @since 6.0
 * 
 */
//Spring Bean的标识.
@Component
//默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class BackPumpReportManager<T> {

	private BackPumpReportDao backDao;
	
	/**
	 * @param coldDao the coldDao to set
	 */
	@Autowired
	public void setBackDao(BackPumpReportDao backDao) {
		this.backDao = backDao;
	}

	@SuppressWarnings("unchecked")
	public List<BackPumpReport> getAllReports() {
		return (List<BackPumpReport>) backDao.findAll(new Sort(Direction.ASC, "id"));
	}
	
	@Transactional(readOnly = false)
	public void saveReport(BackPumpReport report) {
		backDao.save(report);
	}
	
	@Transactional(readOnly = false)
	public BackPumpReport getOneById (Long id){
		return backDao.findById(id);
	}
	
	@Transactional(readOnly = false)
	public List<BackPumpReport> getReportsByCustomerName (String customerName){
		return backDao.findByCustomerName(customerName);
	}
	
	@Transactional(readOnly = false)
	public void deleteReport(Long id) { 
		 backDao.delete(id);
	}
}
